package ctrconfig

import (
	"fmt"
)

var configLoads = make(map[string]func() error)

func RegisterConfigLoad(name string, loadFunc func() error)  {
	if _, exist := configLoads[name]; exist {
		panic(fmt.Sprintf("config load func already registerd for name: %s", name))
	}

	configLoads[name] = loadFunc
	return
}

func ExecConfigLoad(name string) error {
	if _, exist := configLoads[name]; exist == false {
		return fmt.Errorf("no config load func: %s", name)
	}

	return configLoads[name]()
}

var configCheck = make(map[string]func(value string) error)

func RegisterConfigCheck(name string, checkFunc func(value string) error)  {
	if _, exist := configCheck[name]; exist {
		panic(fmt.Sprintf("config check func already registerd for name: %s", name))
	}

	configCheck[name] = checkFunc
	return
}

func ExecConfigCheck(name string, value string) error {
	if _, exist := configCheck[name]; exist == false {
		return nil
	}

	return configCheck[name](value)
}